package com.wzc.hc.controller;
import com.wzc.hc.entity.po.MeetingRoom;
import com.wzc.hc.service.MeetingRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
@author:甲方
@date:2025/3/515:12
*/
@RestController
@RequestMapping("/meetingRoom")
public class MeetingRoomController {

    @Autowired
    private MeetingRoomService meetingRoomService;

    // 查询
    @GetMapping("/getAll")
    public List<MeetingRoom> getAll() {
        return meetingRoomService.list();
    }

    //会议室添加
    @PostMapping("/add")
    public String addMeetingRoom(@RequestBody MeetingRoom meetingRoom) {
        meetingRoomService.save(meetingRoom);
        return "添加成功";
    }

    //会议室删除
    @DeleteMapping("/delete/{id}")
    public String deleteMeetingRoom(@PathVariable("id") Integer id) {
        meetingRoomService.removeById(id);
        return "删除成功";
    }

    //会议室修改
    @PutMapping("/update")
    public String updateMeetingRoom(@RequestBody MeetingRoom meetingRoom) {
        meetingRoomService.updateById(meetingRoom);
        return "修改成功";
    }

    // 查询某个会议室在特定日期和时间点是否开放
    @GetMapping("/isOpenAt/{meetingRoomId}/{date}/{time}")
    public boolean isOpenAt(@PathVariable("meetingRoomId") Integer meetingRoomId,// 会议室ID
                            @PathVariable("date") String date,// 日期
                            @PathVariable("time") String time) {// 时间点
        return meetingRoomService.isOpenAt(meetingRoomId, date, time);
    }

    //场馆添加
    @PostMapping("/add2")
    public String addMeetingRoom2(@RequestBody MeetingRoom meetingRoom) {
        meetingRoomService.save(meetingRoom);
        return "添加成功";
    }

    //场馆删除
    @DeleteMapping("/delete2/{id}")
    public String deleteMeetingRoom2(@PathVariable("id") Integer id) {
        meetingRoomService.removeById(id);
        return "删除成功";
    }

    //场馆修改
    @PutMapping("/update2")
    public String updateMeetingRoom2(@RequestBody MeetingRoom meetingRoom) {
        meetingRoomService.updateById(meetingRoom);
        return "修改成功";
    }

    // 查询某个场馆在特定日期和时间点是否开放
    @GetMapping("/OpenAt/{meetingRoomId}/{date}/{time}")
    public boolean OpenAt(@PathVariable("meetingRoomId") Integer meetingRoomId,// 会议室ID
                            @PathVariable("date") String date,// 日期
                            @PathVariable("time") String time) {// 时间点
        return meetingRoomService.OpenAt(meetingRoomId, date, time);
    }
}